package com.ruoyi.web.controller.mall;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.service.MallOrderService;
import com.ruoyi.mall.domain.MallOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单Controller
 *
 * @author ruoyi
 * @date 2024-01-11
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/mall/order")
public class MallOrderController extends BaseController {
    @Autowired
    private MallOrderService mallOrderService;

    /**
     * 查询订单列表
     */
    @ApiOperation("查询订单列表")
    @PreAuthorize("@ss.hasPermi('mall:order:list')")
    @PostMapping("/list")
    public TableDataInfo list(MallOrder mallOrder) {
        startPage();
        List<MallOrder> list = mallOrderService.selectMallOrderList(mallOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @ApiOperation("导出订单列表")
    @PreAuthorize("@ss.hasPermi('mall:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallOrder mallOrder) {
        List<MallOrder> list = mallOrderService.selectMallOrderList(mallOrder);
        ExcelUtil<MallOrder> util = new ExcelUtil<>(MallOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation("获取订单详细信息")
    @PreAuthorize("@ss.hasPermi('mall:order:query')")
    @PostMapping(value = "getInfo/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return success(mallOrderService.selectMallOrderByOrderId(orderId));
    }

    /**
     * 修改订单
     */
    @ApiOperation("修改订单")
    @PreAuthorize("@ss.hasPermi('mall:order:update')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public AjaxResult update(@RequestBody MallOrder mallOrder) {
        return toAjax(mallOrderService.updateMallOrder(mallOrder));
    }

    /**
     * 删除订单
     */
    @ApiOperation("删除订单")
    @PreAuthorize("@ss.hasPermi('mall:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @PostMapping("remove/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(mallOrderService.deleteMallOrderByOrderIds(orderIds));
    }
}
